package com.example.testapplication.ui.mine;

import static me.goldze.mvvmhabit.utils.Utils.getContext;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.example.testapplication.BR;
import com.example.testapplication.R;
import com.example.testapplication.databinding.FragMineBinding;
import com.example.testapplication.ui.imageselect.ImageSelectActivity;
import com.example.testapplication.ui.setting.SettingActivity;
import com.example.testapplication.ui.userdata.UserDataActivity;
import com.example.testapplication.view.CustomPopup;
import com.example.testapplication.widget.XCollapsingToolbarLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.enums.PopupPosition;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class MineFragment extends BaseFragment<FragMineBinding, MineViewModel>{
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.frag_mine;
    }


    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    @Override
    public void initViewObservable() {
        viewModel.uc.pClickEvent.observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                switch (integer) {
                    case 1:
                        BasePopupView popupView = new XPopup.Builder(getActivity())
                                .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                .popupPosition(PopupPosition.Right)//右边
                                .hasStatusBarShadow(true) //启用状态栏阴影
                                .asCustom(new CustomPopup(getContext()));
                        popupView.show();
                        break;
                    case 2://选择图片
                        ImageSelectActivity.start((BaseActivity) getActivity(), new ImageSelectActivity.OnPhotoSelectListener() {

                            @Override
                            public void onSelected(List<String> data) {
                                ToastUtils.showShort("选择了" + data.toString());
                            }

                            @Override
                            public void onCancel() {
                                ToastUtils.showShort("取消了");
                            }
                        });
                        break;
                    case 3://点击头像
                        startActivity(UserDataActivity.class);
                        break;
                }
            }
        });
    }
}
